import re

import genshi.builder as bldr
#from genshi.core import Attrs, QName, stripentities
#from genshi.core import END, START, TEXT, COMMENT
from creoleparser import core, dialects, parse_args

from model import Page
import macros

def class_func(page_name):
    if not page_name:
        return None
    if Page.get_by_key_name('-'+page_name) is None:
        return 'nonexistent'

def issue_func(mo,e):
    return bldr.tag.a(mo.group(0),href='http://code.google.com/p/creoleparser/issues/detail?id=' + mo.group('id'))
   
dialect = dialects.create_dialect(
    dialects.creole11_base,
    no_wiki_monospace=False,
    blog_style_endings=True,
    wiki_links_class_func=class_func,
    #macro_func=macro_func,
    custom_markup=[(re.compile(core.esc_neg_look + r'issue (?P<id>\d+)(?i)'), issue_func),
                   ('(c)','&copy;'),('(R)','&reg;')],
    non_bodied_macros= macros.non_bodied_macros,
    bodied_macros= macros.bodied_macros,
    add_heading_ids=True
    )


text2html = core.Parser(dialect)

                    
                    
            
    
    
    

